<?php
$title = '策略详情';
/** @var array $script */
/** @var array|null $subscription */
/** @var array $orders */
require __DIR__ . '/../partials/head.php';
require __DIR__ . '/../partials/nav.php';
?>
<section class="section">
    <div class="app-container" style="display:flex;flex-direction:column;gap:24px;">
        <div class="card" style="gap:18px;">
            <div>
                <h2 style="margin-bottom:8px;"><?= htmlspecialchars($script['name']) ?></h2>
                <p style="color:var(--text-secondary);margin:0;">Connector：<?= htmlspecialchars($script['connector']) ?> ｜ 标的：<?= htmlspecialchars(implode(', ', $script['symbols'])) ?></p>
            </div>
            <div class="grid-2">
                <div>
                    <h4>我的订阅状态</h4>
                    <p style="color:var(--text-secondary);">启用：<?= ($subscription['enabled'] ?? false) ? '是' : '否' ?></p>
                    <p style="color:var(--text-secondary);">投入额度：<?= htmlspecialchars((string)($subscription['allocation']['value'] ?? $script['default_target']['value'])) ?> USDT</p>
                </div>
                <div>
                    <h4>策略说明</h4>
                    <p style="color:var(--text-secondary);">策略由管理员维护。基于 TradingView Pine Script v5，信号经控制平面风控后推送至 hummingbot 执行。</p>
                </div>
            </div>
        </div>
        <div class="card" style="gap:18px;">
            <div style="display:flex;justify-content:space-between;align-items:center;">
                <h3 style="margin:0;">最近订单</h3>
                <a class="btn-ghost btn" href="/orders">查看全部</a>
            </div>
            <?php if (empty($orders)): ?>
                <div class="empty-state">
                    <img src="/assets/img/empty/orders.svg" alt="暂无订单">
                    <p>尚无订单记录，等待下一次信号触发。</p>
                </div>
            <?php else: ?>
                <table class="table">
                    <thead>
                    <tr>
                        <th>时间</th>
                        <th>方向</th>
                        <th>数量</th>
                        <th>状态</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($orders as $order): ?>
                        <tr>
                            <td><?= \Frontend\Helpers\Format::datetime($order['created_at'] ?? '') ?></td>
                            <td><?= htmlspecialchars($order['side'] ?? '-') ?></td>
                            <td><?= htmlspecialchars($order['qty'] ?? '-') ?></td>
                            <td><?= htmlspecialchars($order['status'] ?? '-') ?></td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            <?php endif; ?>
        </div>
    </div>
</section>
<?php require __DIR__ . '/../partials/footer.php'; ?>
